package com.next

class ContactTeam
{
    TeamRole teamRole

    User user

    TeamRole contactPermission
    TeamRole activityPermission
    TeamRole teamPermission
    TeamRole attachmentPermission
    TeamRole notePermission
    TeamRole flexFieldPermission
    TeamRole addressPermission

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    User createBy
    User modifyBy

    static mapping = {
        sort 'contact'
    }

    static belongsTo = [contact: Contact]

    static constraints = {
        user unique: ['contact']
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true

        contactPermission nullable: true, blank: true
        activityPermission nullable: true, blank: true
        teamPermission nullable: true, blank: true
        attachmentPermission nullable: true, blank: true
        notePermission nullable: true, blank: true
        flexFieldPermission nullable: true, blank: true
        addressPermission nullable: true, blank: true
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
